﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.admin.pay
{
    public partial class area_manage : System.Web.UI.Page
    {
  
        protected Label Label2;

        // Methods
        private void Bind()
        {
            string str;
            if (base.Request.QueryString["pid"] != null)
            {
                str = "select * from DB_Area where parentid=" + re.replace(base.Request.QueryString["areaid"].ToString()) + "";
            }
            else
            {
                str = "select * from DB_Area where parentid=0";
            }
            DataSet set = SQLAccess.GreatDs(str);
            this.DataList1.DataSource = set;
            this.DataList1.DataBind();
            if (((base.Request.QueryString["action"] != null) && (base.Request.QueryString["areaid"] != null)) && (base.Request.QueryString["action"].ToString() == "del"))
            {
                string sql = "select top 1 * from DB_Area where areaid=" + base.Request.QueryString["areaid"];
                DataTable table = new DataTable();
                table = SQLAccess.GreatDs(sql).Tables[0];
                string str3 = table.Rows[0]["parentid"].ToString();
                string str4 = table.Rows[0]["typeid"].ToString();
                SQLAccess.DoSql("delete from DB_Area where areaid=" + base.Request.QueryString["areaid"].ToString() + "");
                SQLAccess.DoSql("delete from DB_Area where parentid=" + base.Request.QueryString["areaid"].ToString() + "");
                base.Response.Write("<script language='javascript'>window.location.href='area_manage.aspx?areaid=" + str3 + "&pid=" + str4 + "';</script>");
                base.Response.End();
            }
        }

        public void DataList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                HyperLink link = (HyperLink)e.Item.FindControl("HyperLink1");
                Label label = (Label)e.Item.FindControl("Labelid");
                Label label2 = (Label)e.Item.FindControl("Labeltypeid");
                link.NavigateUrl = string.Concat(new object[] { "area_manage.aspx?areaid=", label.Text, "&pid=", Convert.ToInt64(label2.Text.ToString()) + 1L, "" });
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string str2;
            string str3;
            if (base.Request.QueryString["areaid"] != null)
            {
                str2 = base.Request.QueryString["areaid"].ToString();
            }
            else
            {
                str2 = "0";
            }
            if (base.Request.QueryString["pid"] != null)
            {
                str3 = base.Request.QueryString["pid"].ToString();
            }
            else
            {
                str3 = "1";
            }
            SQLAccess.DoSql("insert into DB_Area (parentid,area,amont,typeid) values (" + re.replace(str2.ToString()) + ",'" + re.replace(this.area.Value) + "',0," + re.replace(str3.ToString()) + ")");
            base.Response.Write("<script language='javascript'>window.location.href='area_manage.aspx?areaid=" + str2.ToString() + "&pid=" + str3.ToString() + "';</script>");
            base.Response.End();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='../login.aspx';</script>");
                base.Response.End();
            }
            if (!base.IsPostBack)
            {
                this.Bind();
                if (base.Request.QueryString["areaid"] != null)
                {
                    this.upbind();
                }
                if (base.Request.QueryString["pid"] != null)
                {
                    if (base.Request.QueryString["pid"].ToString() == "1")
                    {
                        this.Label1.Text = "一";
                        this.Label2.Text = "一";
                    }
                    if (base.Request.QueryString["pid"].ToString() == "2")
                    {
                        this.Label1.Text = "二";
                        this.Label2.Text = "二";
                    }
                    if (base.Request.QueryString["pid"].ToString() == "3")
                    {
                        this.Label1.Text = "三";
                        this.Label2.Text = "三";
                    }
                    if (base.Request.QueryString["pid"].ToString() == "4")
                    {
                        this.Label1.Text = "四";
                        this.Label2.Text = "四";
                    }
                    if (base.Request.QueryString["pid"].ToString() == "5")
                    {
                        this.Label1.Text = "五";
                        this.Label2.Text = "五";
                    }
                }
                else
                {
                    this.Label1.Text = "一";
                    this.Label2.Text = "一";
                }
            }
        }

        private void upbind()
        {
            string sql = "select top 1 * from DB_Area where areaid=" + base.Request.QueryString["areaid"];
            new DataTable();
            DataTable table1 = SQLAccess.GreatDs(sql).Tables[0];
        }


    }
}